package com.lzl.redisratelimit.controller;

import com.lzl.redisratelimit.annotation.RateLimit;
import com.lzl.redisratelimit.annotation.RateLimitKey;
import com.lzl.redisratelimit.util.RateLimiter;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    private RateLimiter rateLimiter;


    @PostMapping("/limit")
    @RateLimit(scene = "test")
    public String testLimit(@RequestBody Request request){
        if(rateLimiter.isLimit("test","zhangsan",5,1,20)){
            throw new RuntimeException("被限流了");
        }
        return "pass";
    }


    @GetMapping("/limit")
    @RateLimit
    public String testLimit1(@RequestParam @RateLimitKey String userId){

        return "pass";
    }
}
